
"""
文笔写作评分
"""
from models import Novel
from pydantic import Field
from core.utils import BaseAnalyzer, prompt_dir


class StyleRating(BaseAnalyzer):

    def __init__(self):
        super().__init__(prompt_file=prompt_dir / 'rating/r4. 文笔写作评分.md')

    def invoke(
            self,
            novel: Novel = Field(description="小说")
    ):
        all_styles = {
            chapter.chapter_title: chapter.writing_style for chapter in novel.chapters
        }
        prompt = self.template_prompt.format(
            inputs={
                "topn": novel.topn,
                "writing_style": all_styles
            },
            remove_template_variables=True
        )
        novel.style_rating = self.analyze(prompt)
        return novel.style_rating
